package io.iostream;

import io.file.FileDemoX;

import java.io.*;

public class IODemo1 {
    public static boolean copyFile(String s, String s1) {
        BufferedInputStream bis=null;
        BufferedOutputStream bos=null;
        try {
            bis=new BufferedInputStream(new FileInputStream(s));
            FileDemoX.createF(s);
            bos=new BufferedOutputStream(new FileOutputStream(s1));
            byte[] bytes=new byte[1024];

            int len=bis.read(bytes);
            while (len!=-1){
                len=bis.read(bytes);
                bos.write(bytes);
            }
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }finally {
            if(bis!=null){
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(bos!=null){
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
